<?php

declare(strict_types=1);

namespace SixShop\Wangdian\Services;

use SixShop\Wangdian\Response\ApiResponse;

/**
 * Purchase service for purchase orders, returns, etc.
 */
class PurchaseService extends BaseService
{
    /**
     * Push purchase order
     */
    public function pushOrder(array $orderData): ApiResponse
    {
        $this->validateRequired($orderData, ['purchase_info']);

        return $this->call('purchase_order_push.php', [
            'purchase_info' => $this->encodeIfArray($orderData['purchase_info']),
        ]);
    }

    /**
     * Query purchase order
     */
    public function queryOrder(array $params = []): ApiResponse
    {
        return $this->call('purchase_order_query.php', $this->filterParams($params));
    }

    /**
     * Push purchase return order
     */
    public function pushReturnOrder(array $returnData): ApiResponse
    {
        $this->validateRequired($returnData, ['return_info']);

        return $this->call('purchase_return_order_push.php', [
            'return_info' => $this->encodeIfArray($returnData['return_info']),
        ]);
    }

    /**
     * Push purchase return
     */
    public function pushReturn(array $returnData): ApiResponse
    {
        return $this->call('purchase_return_push.php', 
            $this->filterParams($returnData)
        );
    }

    /**
     * Query purchase return
     */
    public function queryReturn(array $params = []): ApiResponse
    {
        return $this->call('purchase_return_query.php', $this->filterParams($params));
    }

    /**
     * Push stockin purchase
     */
    public function pushStockinPurchase(array $stockinData): ApiResponse
    {
        return $this->call('stockin_purchase_push.php', 
            $this->filterParams($stockinData)
        );
    }

    /**
     * Query stockin order for purchase
     */
    public function queryStockinOrder(array $params = []): ApiResponse
    {
        return $this->call('stockin_order_query_purchase.php', $this->filterParams($params));
    }

    /**
     * Query stockout return order
     */
    public function queryStockoutReturnOrder(array $params = []): ApiResponse
    {
        return $this->call('stockout_return_order_query.php', $this->filterParams($params));
    }
}